import {HttpClient} from '@angular/common/http';
import { Component, Input, OnInit, Output } from '@angular/core';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import {FormControl, FormGroupDirective, NgForm, Validators} from '@angular/forms';
import {ErrorStateMatcher} from '@angular/material/core';



/** Error when invalid control is dirty, touched, or submitted. */
export class MyErrorStateMatcher implements ErrorStateMatcher {
  isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
    const isSubmitted = form && form.submitted;
    return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
  }
}
  
@Component({
  selector: 'app-staff-addor-edit',
  templateUrl: './staff-addor-edit.component.html',
  styleUrls: ['./staff-addor-edit.component.css']
})

export class StaffAddorEditComponent {

  staffId:number;
  staffName:string;
  staffAge:number;
  staffGender:boolean;
  staffInTime:Date;

  startDate = new Date(1990, 0, 1);
   
  constructor(private router:Router,public http:HttpClient) { }

  ngOnInit(){
    console.log(localStorage["staffid"])
    let api='https://localhost:44312/api/staff/'+localStorage["staffid"];
    this.http.get(api).subscribe((res:any)=>{
      console.log(res);
      if(res.state=1)
      {
        this.staffName=res.data.staffName;
        this.staffAge=res.data.staffAge;
        this.staffGender=res.data.staffGender;
        this.staffInTime=res.data.staffInTime;
        this.staffId=res.data.staffId;
        console.log(this.staffGender)
      }
    })
    
  }

  toSubmit()
  {
    console.log(this.staffId);
    console.log(this.staffName);
    console.log(this.staffAge);
    console.log(this.staffGender);
    console.log(this.staffInTime);

  }

  numberFormContorl=new FormControl('',[
    Validators.required
  ]);

  nameFormControl=new FormControl('',[
    Validators.required
  ])
  matcher=new MyErrorStateMatcher();

}
